package edu.tsinghua.mrpvc.device.frige;


import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;

import edu.tsinghua.mrpvc.device.FrigeDevice;
//import edu.tsinghua.mrpvc.simulate.util.SimulateTopic;

public class Activator implements BundleActivator, EventHandler {
//	private FrigeDeviceImpl frige;
//	private static final String[] RESPONSE_TOPICS = {FrigeDevice.EVENT_TOPIC_ISVALID};
	//private static final String[] SIMULATE_TOPICS = {SimulateTopic.FRIGE_FOOD_IN, SimulateTopic.FRIGE_FOOD_OUT};
	
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
//		frige = new FrigeDeviceImpl(context, "1");
//		
//		context.registerService(FrigeDevice.class.getName(), frige, null);
//		
//		Dictionary<String, Object> proper = new Hashtable<String, Object>();
//		proper.put(EventConstants.EVENT_TOPIC, RESPONSE_TOPICS);
//		context.registerService(EventHandler.class.getName(), frige, proper);
		
		//Dictionary<String, Object> simProper = new Hashtable<String, Object>();
		//simProper.put(EventConstants.EVENT_TOPIC, SIMULATE_TOPICS);
		//context.registerService(EventHandler.class.getName(), this, simProper);
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
	}

	@Override
	public void handleEvent(Event event) {
		// TODO Auto-generated method stub
		//if(event.getTopic().equals(SimulateTopic.FRIGE_FOOD_IN) && 
		//		event.getProperty(FrigeDevice.EVENT_PROPER_FOOD_NAME) != null){
		//	frige.sendInFood(event.getProperty(FrigeDevice.EVENT_PROPER_FOOD_NAME).toString());
		//}
		//else if(event.getTopic().equals(SimulateTopic.FRIGE_FOOD_OUT) &&
		//		event.getProperty(FrigeDevice.EVENT_PROPER_FOOD_NAME) != null){
		//	frige.takeOutFood(event.getProperty(FrigeDevice.EVENT_PROPER_FOOD_NAME).toString());
		//}	
	}

}
